package com.yxkj.syh.app.huarong.adps;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.recyclerview.widget.RecyclerView;

import com.syh.app.basic.base.BaseAdp;
import com.yxkj.syh.app.huarong.BR;
import com.yxkj.syh.app.huarong.R;
import com.yxkj.syh.app.huarong.bean.OrderInfo;
import com.yxkj.syh.app.huarong.bean.ReturnCar;

/**
 * 创建者：SYH
 * 时间：2020/5/25 16:16
 * 编辑者：SYH、
 * 标签：
 * 补充说明：
 */
public class ReturnCarListAdp extends BaseAdp<ReturnCar> {
    private OnViewClick mOnViewClick;

    @Override
    protected RecyclerView.ViewHolder createYourViewHolder(@NonNull ViewGroup parent, int viewType) {
        ViewDataBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.item_ruturn_cars, parent, false);
        View view = binding.getRoot();
        view.setTag(binding);
        return new ViewHolder(view);
    }

    @Override
    protected void bindYourViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        if (mOnViewClick != null) {
            holder.itemView.setOnClickListener(v -> {
                mOnViewClick.onItem(mData.get(position));
            });
        }
        ViewDataBinding binding = (ViewDataBinding) holder.itemView.getTag();
        binding.setVariable(BR.returnCar, mData.get(position));
        binding.executePendingBindings();
    }

    public void setOnViewClick(OnViewClick onViewClick) {
        this.mOnViewClick = onViewClick;
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
        }
    }

    public interface OnViewClick {
        void onItem(ReturnCar car);
    }

}
